package com.ruoyi.mobile.project.oms.service;

import com.ruoyi.db.oms.domain.OmsOrderGoods;
import com.ruoyi.db.oms.domain.query.OmsOrderGoodsQueryVo;
import com.ruoyi.db.oms.domain.query.OmsOrderQueryVo;
import com.ruoyi.db.oms.mapper.OmsOrderGoodsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class WxOmsOrderGoodsService
{
    @Autowired
    private OmsOrderGoodsMapper orderGoodsMapper;

    /**
     * 添加订单商品
     *
     * @author 严方亚
     * @date 2020-05-22
     * @param orderGoods
     */
    public int add(OmsOrderGoods orderGoods)
    {
        orderGoods.setAddTime(LocalDateTime.now());
        orderGoods.setUpdateTime(LocalDateTime.now());
        return orderGoodsMapper.insertOmsOrderGoods(orderGoods);
    }

    /**
     * 根据OrderId查询商品列表
     * @author 严方亚
     * @date 2020-05-12
     * @param orderId
     * @return
     */
    public List<OmsOrderGoods> queryByOid(Long orderId)
    {
        return orderGoodsMapper.getOrderGoodsList(orderId);
    }

    /**
     * 获取订单商品列表
     *
     * @author 严方亚
     * @date 2020-05-17
     * @param orderId
     * @param goodsId
     */
    public List<OmsOrderGoods> findByOidAndGid(Long orderId, Long goodsId)
    {
        OmsOrderGoodsQueryVo orderGoodsQueryVo = new OmsOrderGoodsQueryVo();
        orderGoodsQueryVo.setOrderId(orderId);
        orderGoodsQueryVo.setGoodsId(goodsId);
        return orderGoodsMapper.getOrderGoodsListNotDeleted(orderGoodsQueryVo);
    }

    /**
     * 根据订单商品id获取订单商品信息
     *
     * @author 严方亚
     * @date 2020-05-17
     * @param id
     */
    public OmsOrderGoods findById(Long id)
    {
        return orderGoodsMapper.getOrderGoods(id);
    }

    public void updateById(OmsOrderGoods orderGoods)
    {
        orderGoods.setUpdateTime(LocalDateTime.now());
        orderGoodsMapper.updateOmsOrderGoods(orderGoods);
    }

    /**
     * 查询订单商品评论数量
     *
     * @author 严方亚
     * @date 2020-05-14
     * @param orderId
     */
    public Integer getComments(Long orderId)
    {
        OmsOrderGoodsQueryVo orderGoodsQueryVo = new OmsOrderGoodsQueryVo();
        orderGoodsQueryVo.setOrderId(orderId);
        Integer count = orderGoodsMapper.getCommentsCount(orderGoodsQueryVo);
        return count;
    }

    public boolean checkExist(Long goodsId)
    {
        return true;
    }
}
